package com.qbw.app.utils;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.DisplayMetrics;

import com.lib.util.SPUtils;

import java.util.Locale;

public class LanguageUtils {

    public static void setdefaultLanguage(Context context, String language) {
        Locale locale = new Locale(language);
//        Locale.setDefault(locale);

        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        if("en".equals(language)){
            Configuration config = context.getResources().getConfiguration();
            config.locale = Locale.ENGLISH;
            context.getResources().updateConfiguration(config, metrics);
        }else  if("zh".equals(language)){
            Configuration config = context.getResources().getConfiguration();
            config.locale =  Locale.SIMPLIFIED_CHINESE;
            context.getResources().updateConfiguration(config, metrics);
        }else{
            Configuration config = Resources.getSystem().getConfiguration();
            context.getResources().updateConfiguration(config, metrics);
        }
        SPUtils.getInstance().put("language",language);

    }




}
